<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It is a breeze. Simply tell Lumen the URIs it should respond to
| and give it the Closure to call when that URI is requested.
|
*/

$router->get('/', function () use ($router) {
    return $router->app->version();
});
$router->get('/dl/{user_file_id}',['uses'=>'FileController@download']);
$router->get('/wxqyh/{app_name}', function ($app_name) use ($router) {
    $corpid = \Illuminate\Support\Facades\DB::table('settings')->where("name", "QYH_CORPID")->value('value');//env("QYH_CORPID");
    $agentid = \Illuminate\Support\Facades\DB::table('settings')->where("name", "QYH_AGENTID")->value('value');//env("QYH_AGENTID");
    $auth_url = "https://open.weixin.qq.com/connect/oauth2/authorize?";
    $redirect_uri = "";
    if($app_name==="netdisk") {
        $redirect_uri = urlencode(Illuminate\Support\Facades\Request::server ('SERVER_NAME')."/login/wxqyh");
    }
    return redirect($auth_url."appid={$corpid}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&agentid={$agentid}&state={$app_name}#wechat_redirect");
});
$router->post('/upload/auth', ['middleware'=>'auth', 'uses'=>'FileController@uploadAuth']);
$router->post('/upload', ['uses'=>'FileController@upload']);
$router->get('/download/auth/{id}', ['middleware'=>'auth', 'uses'=>'FileController@downloadAuth']);
$router->get('/download/{access_token}', ['uses'=>'FileController@download']);
$router->get('/login/wxqyh', ['uses'=>'UserController@wxqyhLogin']);
$router->get('/apply_netdisk', ['middleware'=>'auth', 'uses'=>'ApplyController@apply']);

$router->get('/user_file/root', ['middleware'=>'auth', 'uses'=>'UserFileController@getRootInfo']);
$router->get('/user_file/parent/{id}', ['middleware'=>'auth', 'uses'=>'UserFileController@getParentId']);
$router->get('/user_file/create', ['middleware'=>'auth', 'uses'=>'UserFileController@createFolder']);
$router->get('/user_file/delete/{id}', ['middleware'=>'auth', 'uses'=>'UserFileController@deleteUserFile']);
$router->get('/user_file/folder', ['middleware'=>'auth', 'uses'=>'UserFileController@getFolderInfo']);
$router->get('/user_file/detail/{id}', ['middleware'=>'auth', 'uses'=>'UserFileController@detail']);
$router->get('/user_file/links', ['middleware'=>'auth', 'uses'=>'UserFileController@getLinks']);
$router->get('/user_file/forward/{id}', ['middleware'=>'auth', 'uses'=>'UserFileController@forward']);
$router->get('/user_file/search', ['middleware'=>'auth', 'uses'=>'UserFileController@search']);
$router->get('/user_file/rename/{id}', ['middleware'=>'auth', 'uses'=>'UserFileController@rename']);
$router->get('/user_file/folders', ['middleware'=>'auth', 'uses'=>'UserFileController@getAllFolders']);
$router->get('/user_file/move/{id}', ['middleware'=>'auth', 'uses'=>'UserFileController@moveToFolder']);

$router->get('/collect_file/files', ['middleware'=>'auth', 'uses'=>'CollectFileController@getFiles']);
$router->get('/collect_file/collect/{id}', ['middleware'=>'auth', 'uses'=>'CollectFileController@collect']);
$router->get('/collect_file/cancel/{id}', ['middleware'=>'auth', 'uses'=>'CollectFileController@cancel']);

$router->get('/users', ['middleware'=>'auth', 'uses'=>'UserController@getUsers']);

$router->get('/index', ['uses'=>'ViewController@show_index']);
$router->get('/userList', ['uses'=>'ViewController@show_userList']);
$router->get('/create', ['uses'=>'ViewController@show_create']);
$router->get('/detail', ['uses'=>'ViewController@show_detail']);
$router->get('/list', ['uses'=>'ViewController@show_list']);
$router->get('/list_fav', ['uses'=>'ViewController@show_list_fav']);
$router->get('/list_at', ['uses'=>'ViewController@show_list_at']);
$router->get('/list_search', ['uses'=>'ViewController@show_list_search']);
$router->get('/apply', ['uses'=>'ViewController@show_apply']);
$router->get('/apply_success', ['uses'=>'ViewController@show_apply_success']);
$router->get('/error', ['uses'=>'ViewController@show_error']);
$router->get('/list_folder', ['uses'=>'ViewController@show_list_folder']);

$router->get('/dashboard/login', function () use ($router) {return view('admin.login');});
$router->post('/dashboard/login', ['uses'=>'Dashboard\\AdminController@login']);
$router->group(['namespace'=>'Dashboard', 'prefix'=>'dashboard', 'middleware'=>'auth:admin'], function () use ($router) {
    $router->get('/', ['uses'=>'UserController@getUsers']);
    $router->get("/list_user", ['uses'=>'UserController@getUsers']);
    $router->get("/user/{id}", ['uses'=>'UserController@getOneUser']);
    $router->post("/modify_user/{id}", ['uses'=>'UserController@modify']);
    $router->get("/enable_user/{id}", ['uses'=>'UserController@enable_user']);
    $router->get("/disable_user/{id}", ['uses'=>'UserController@disable_user']);
    $router->get("/delete/{id}", ['uses'=>'UserController@delete']);
    $router->get('/logout', ['uses'=>'AdminController@logout']);
    $router->get("/setting", ['uses'=>'AdminController@showSetting']);
    $router->post('/setting/{id}', ['uses'=>'AdminController@setting']);
    $router->get('/password', function () { return view('admin.password'); });
    $router->post('/password', ['uses'=>'AdminController@updatePassword']);
    $router->get("/list_apply", ['uses'=>'ApplyController@getApplies']);

    $router->get("/sync/init", ['uses'=>'UserController@getDepartments']);
    $router->get("/sync/{department_id}", ['uses'=>'UserController@syncUsers']);
});


